{%- set leftK = "{" -%}
{%- set rightK = "}" -%}
{%- set leftdK = "{{" -%}
{%- set rightdK = "}}" -%}
{%- set md = "$" -%}
{%- set kg = "" -%}
{%- set items = "" -%}
{%- set itemNames = "" -%}
{%- set isUpload = false -%}
{%- set isTextEdit = false -%}
{%- set componentsU = '' -%}
<template>
    <el-dialog title='编辑' :visible.sync="formVisible">  
      <el-form :rules="rules" ref="dataForm" :model="editData" label-position="left" label-width="70px" style=''> 
      {%- for f in fields %}
      {%- if (f.colType.type=='datetime') %}
       <el-form-item :label="{{md}}t('table.{{tableName}}.{{f.javaFname}}')" prop="{{f.javaFname}}">
          <el-date-picker v-model="editData.{{f.javaFname}}" type="datetime"  value-format="timestamp" placeholder="Please pick {{f.javaFname}}">
          </el-date-picker>
       </el-form-item>  
      {%- elif (f.colType.type=='boolean') %} 
       <el-form-item :label="{{md}}t('table.{{tableName}}.{{f.javaFname}}')">
         {%- set items = items+"const "+f.javaFname+'Maps = '+f.colType.mapsStr+"\n" -%}
         {%- set itemNames = itemNames+f.javaFname+'Maps,\n'-%}
         <el-select class="filter-item" v-model="editData.{{f.javaFname}}" placeholder="Please select {{f.javaFname}}">           
           <el-option v-for="item in  {{f.javaFname+'Maps'}}" :key="item.value" :label="item.name" :value="item.value">
           </el-option>           
         </el-select>
       </el-form-item>
      {%- elif (f.colType.type=='upLoad') %}
      {%- set isUpload = true -%}      
       {% if componentsU=='' %}
       {%- set componentsU =componentsU+"Upload"  -%}       
      {% else %}
        {%- set componentsU =componentsU+", Upload"  -%}
      {% endif %}  
      <el-form-item :label="{{md}}t('table.{{tableName}}.{{f.javaFname}}')" prop="{{f.javaFname}}">
           <Upload v-model="editData.{{f.javaFname}}"></Upload>  
      </el-form-item>
      {%- elif (f.colType.type=='text') %}
      {%- set isTextEdit = true -%}
      {% if componentsU=='' %}
       {%- set componentsU =componentsU+"Tinymce"  -%}       
      {% else %}
        {%- set componentsU =componentsU+", Tinymce"  -%}
      {% endif %}     
      <el-form-item :label="{{md}}t('table.{{tableName}}.{{f.javaFname}}')" prop="{{f.javaFname}}">
         <tinymce :height=400 ref="editor" v-model="editData.{{f.javaFname}}"></tinymce> 
      </el-form-item>       
      {%- else %}           
       <el-form-item :label="{{md}}t('table.{{tableName}}.{{f.javaFname}}')" prop="{{f.javaFname}}">
          <el-input v-model="editData.{{f.javaFname}}"></el-input>
       </el-form-item>
      {%- endif %}
      {%- endfor -%}  
       </el-form>  
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">{{leftdK}}{{md}}t('table.cancel'){{rightdK}}</el-button>       
        <el-button type="primary" @click="update">{{leftdK}}{{md}}t('table.confirm'){{rightdK}}</el-button>
      </div>
    </el-dialog>
</template>
<script>
import { {{tableName}}Patch } from '@/api/{{tableName}}'
{%- if (isUpload==true) -%}
{{"\nimport Upload from '@/components/Upload/singleImage2'"|safe}}
{%- endif %}
{%- if (isTextEdit==true) -%}
{{"\nimport Tinymce from '@/components/Tinymce'"|safe}}
{%- endif %}
{{items|safe}}
export default {
  name: '{{tableName}}EditDialog',
  props: ['Visible', 'editData'],
  components: {{leftK}}{%- if componentsU != '' -%}{{(' '+componentsU+' ')|safe}}{%-else-%}{{kg}}{%-endif-%}{{rightK}},
  data() {
    return {
      {{itemNames|safe-}}
      {%- if (itemNames!="") -%}
      {{'      '}}
      {%- endif -%}
      formVisible: this.Visible,
      rules: {
        {%- for f in fields %}
        {{f.javaFname}}: [{ required: true, message: '{{f.javaFname}} is required', trigger: 'change' }]{%- if loop.last != true -%},{%- else -%}{{kg}}{%- endif -%}
        {%-endfor%}
      }
    }
  },
  methods: {
    update() {
      console.log(this.editData)
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const tempData = Object.assign({}, this.editData)
          delete tempData.lastLoginTime
          {{tableName}}Patch(tempData).then(() => {
            // for (const v of this.list) {
            //   if (v.id === this.temp.id) {
            //     const index = this.list.indexOf(v)
            //     this.list.splice(index, 1, this.temp)
            //     break
            //   }
            // }
            this.$emit('hiddenEditDialog')
            this.$notify({
              title: '成功',
              message: '更新成功',
              type: 'success',
              duration: 2000
            })
          })
        }
      })
    },
    cancel() {
      this.$emit('hiddenEditDialog')
    }
  },
  watch: {
    Visible(val) {
      this.formVisible = val
    },
    formVisible(val) {
      if (val === false) {
        this.$emit('hiddenEditDialog')
      }
    }
  }
}
</script>

